#include <stdio.h>

void bubblesort(int arr[], int size)
{
	int i = 0;
	int count = 0;
	for (i = 0; i < size - 1; i++)
	{
		int flag = 1;
		int j = 0;
			for (j = 0; j < size - 1; j++)
			{
				if (arr[j] > arr[j + 1])
				{
					int temp = 0;
					temp = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = temp;
					flag = 0;
					count++;
				}
			}
			if (flag == 1)
			{
				break;
			}
	}
	printf("%d\n", count);
}


int main()
{
	int arr[10] = { 8,7,9,4,6,5,1,3,2,0 };
	//int arr[10] = { 0,1,2,3,4,5,6,7,8,9 };
	int i = 0;
	for (i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	bubblesort(arr, 10);
	
	for (i = 0; i < 10; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	return 0;
}